content = """
# 引用
>>> a = 1
>>> b = a
>>> id(a)
1950051344
>>> id(b)
1950051344

# List-creat
>>> l = []
>>> l.append('a')
>>> l
['a']

>>> l = ["你好"]
>>> l.append("世界")
>>> l
['你好', '世界']

>>> l = ["你好"]
>>> l.append("3.1415926")
>>> l
['你好', '3.1415926']

# + 和 +=
>>> l_1 = ["a"]
>>> l_2 = ["b"]
>>> l_3 = l_1 + l_2
>>> l_3
['a', 'b']
>>> id(l_1)
1592775398600
>>> id(l_2)
1592775398664
>>> id(l_3)
1592775399048

# insert
>>> l = ["a","b"]
>>> l.insert(0,"c")
>>> l
['c', 'a', 'b']
>>> l.insert(1,"c")
>>> l
['c', 'c', 'a', 'b']
>>> l.insert(1,"d")
>>> l
['c', 'd', 'c', 'a', 'b']

# 如果索引位置超过list长度,则会在末尾添加元素
>>> l.insert(5,"f")
>>> l
['c', 'd', 'c', 'a', 'b', 'f']
>>> l.insert(10,"k")
>>> l
['c', 'd', 'c', 'a', 'b', 'f', 'k']

# 索引取值
>>> l = ["你好","3.1415","None"]
>>> l[1]
'3.1415'
>>> l[2]
'None'

# 切片
#取间隔,如果不指定start,则默认是0.如果不指定end,则默认是最后一位.
your_list[start:end:step]

>>> l = ["你好","3.1415","None"]
>>> l[-1]
'None'
>>> l = list(range(50))
>>> l
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22
, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42,
 43, 44, 45, 46, 47, 48, 49]
>>> l[0:21:3]
[0, 3, 6, 9, 12, 15, 18]
>>> l[:21:3]
[0, 3, 6, 9, 12, 15, 18]
>>> l[::6]
[0, 6, 12, 18, 24, 30, 36, 42, 48]


# 取一段区间
your_list[start:end]

>>> l = list(range(100))
>>> l
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22
, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42,
 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62,
63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 8
3, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99]
>>> l[0:11]
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
>>> l[20:31]
[20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]
>>> l[50:-1]
[50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69,
70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 9
0, 91, 92, 93, 94, 95, 96, 97, 98]
>>> l[50:101]
[50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69,
70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 9
0, 91, 92, 93, 94, 95, 96, 97, 98, 99]
>>> l[-1]
99
>>> l[-2]
98
>>> l[-0]
0

# 获取某个元素的下标
>>> l = ["a","b","c","d"]
>>> l.index("d")
3

# 查询到下标后,配合insert,可以在指定位置添加元素
>>> l.insert(l.index("c"),"你好")
>>> l
['a', 'b', '你好', 'c', 'd']


>>> l.index("f")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: 'f' is not in list

# 索引赋值
>>> l = ['a', 'b', '你好', 'c', 'd']
>>> l
['a', 'b', '你好', 'c', 'd']
>>> l[3] = "世界"
>>> l
['a', 'b', '你好', '世界', 'd']

#对元素更改后,不会更改列表的内存地址.
>>> l = ['a', 'b', '你好', 'c', 'd']
>>> l
['a', 'b', '你好', 'c', 'd']
>>> id(l)
1592775399816
>>> l[3] = "世界"
>>> l
['a', 'b', '你好', '世界', 'd']
>>> id(l)
1592775399816

# 切片赋值
>>> l = ['a', 'b', '你好', 'c', 'd']
>>> l[0:2] = ["hello","world"]
>>> l
['hello', 'world', '你好', 'c', 'd']
>>> l[0:2] = ["hello"]
>>> l
['hello', '你好', 'c', 'd']

# 1是个单个值,会报错
>>> l[0:2] = 1
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: can only assign an iterable

# 字符串是序列,不会报错
>>> l[0:2] = "1"
>>> l
['1', 'c', 'd']

# pop()--从末尾删除元素并返回
>>> l = ['a', 'b', '你好', 'c', 'd']
>>> l
['a', 'b', '你好', 'c', 'd']
>>> x = l.pop()
>>> x
'd'
>>> l
['a', 'b', '你好', 'c']

# clear()
>>> l = ['a', 'b', '你好', 'c', 'd']
>>> l
['a', 'b', '你好', 'c', 'd']
>>> l.clear()
>>> l
[]

# sort
>>> l = [2,5,6,3,1,0]
>>> l
[2, 5, 6, 3, 1, 0]
>>> l.sort()
>>> l
[0, 1, 2, 3, 5, 6]

# sorted
>>> l = [2,5,6,3,1,0]
>>> l
[2, 5, 6, 3, 1, 0]
>>> l2 = sorted(l)
>>> l2
[0, 1, 2, 3, 5, 6]
>>> id(l)
1592775399816
>>> id(l2)
1592775397960

# 倒序
>>> l = [2,5,6,3,1,0]
>>> l
[2, 5, 6, 3, 1, 0]
>>> l.reverse()
>>> l
[0, 1, 3, 6, 5, 2]

# reversed
>>> l = [2,5,6,3,1,0]
>>> l
[2, 5, 6, 3, 1, 0]
>>> list(reversed(l))
[0, 1, 3, 6, 5, 2]

# 元祖
# 索引取值,index,切片
>>> t = (1,"hello",None)
>>> t
(1, 'hello', None)
>>> t[0]
1
>>> t[1]
'hello'

>>> t.index(None)
2

>>> t[0:1]
(1,)

#字典  键对值赋值
>>> d = {}
>>> d["a"] = "hello"
>>> d
{'a': 'hello'}

#字典 update
>>> d = {}
>>> d["a"] = "hello"
>>> d
{'a': 'hello'}
>>> d2 = {"b":2,"c":3}
>>> d.update(d2)
>>> d
{'a': 'hello', 'b': 2, 'c': 3}

# 字典 setdefault
>>> d
{'a': 'hello', 'b': 2, 'c': 3}
>>> d.setdefault('a',0)
'hello'
>>> d.setdefault('b',0)
2
>>> d.setdefault('e',"world")
'world'
>>> d
{'a': 'hello', 'b': 2, 'c': 3, 'e': 'world'}

# 字典键对值访问
>>> d = {'a': 'hello', 'b': 2, 'c': 3, 'e': 'world'}
>>>
>>> d
{'a': 'hello', 'b': 2, 'c': 3, 'e': 'world'}
>>> d["e"]
'world'

#如果没有key,则会报错
>>> d["f"]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
KeyError: 'f'

# 字典 get   不会报错,返回None
>>> d = {'a': 'hello', 'b': 2, 'c': 3, 'e': 'world'}
>>> d
{'a': 'hello', 'b': 2, 'c': 3, 'e': 'world'}
>>> d.get("e")
'world'
>>> d.get("f")
>>>
>>> d.get("f",0)
0
>>> d.get("f","错误")
'错误'

# .keys()
>>> d = {'a': 'hello', 'b': 2, 'c': 3, 'e': 'world'}
>>> d
{'a': 'hello', 'b': 2, 'c': 3, 'e': 'world'}
>>> d.keys()
dict_keys(['a', 'b', 'c', 'e'])

# .values()
>>> d = {'a': 'hello', 'b': 2, 'c': 3, 'e': 'world'}
>>> d.values()
dict_values(['hello', 2, 3, 'world'])

# .items()
>>> d.items()
dict_items([('a', 'hello'), ('b', 2), ('c', 3), ('e', 'world')])

# 键对值赋值
>>> d = {'a': 'hello', 'b': 2, 'c': 3, 'e': 'world'}
>>> d["a"] = "你好"
>>> d
{'a': '你好', 'b': 2, 'c': 3, 'e': 'world'}

# update
>>> d.update({"a":100,"f":None})
>>> d
{'a': 100, 'b': 2, 'c': 3, 'e': 'world', 'f': None}

# .pop()
>>> d = {'a': 'hello', 'b': 2, 'c': 3, 'e': None}
>>> d
{'a': 'hello', 'b': 2, 'c': 3, 'e': None}
>>> d.pop("a")
'hello'
>>> d
{'b': 2, 'c': 3, 'e': None}
>>> d.pop("e")
>>> d
{'b': 2, 'c': 3}

# .popitem()
>>> d = {'a': 'hello', 'b': 2, 'c': 3, 'e': None}
>>> d.popitem()
('e', None)

#注意,原来的字典会删除随机的item
>>> d = {'a': 'hello', 'b': 2, 'c': 3, 'e': None}
>>> d.popitem()
('e', None)
>>> d
{'a': 'hello', 'b': 2, 'c': 3}


# set  creat
>>> s
set()
>>> s.add("hello")
>>> s
{'hello'}
>>> s.add("world")
>>> s
{'world', 'hello'}
>>> s.add("python")
>>> s
{'world', 'hello', 'python'}

# Retrieve
>>> s
{'world', 'hello', 'python'}
>>> "python" in s
True
>>> "wolf" in s
False

# update
>>> s
{'world', 'hello', 'python'}
>>> s_2 = {"a","b"}
>>> s.union(s_2)
{'world', 'python', 'hello', 'b', 'a'}

# Delete 
>>> s.remove("wolf")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
KeyError: 'wolf'

>>> s.discard("wolf")
#不会报错

# .pop()--随机无序删除并返回删除的元素
>>> s = {'world', 'hello', None,"[1,2,'python',None]"}
>>> s
{'world', "[1,2,'python',None]", 'hello', None}
>>> s.pop()
'world'

>>> s = {'world', 'hello', None,"[1,2,'python',None]","(1,'hello',None)"}
>>> s
{'world', "[1,2,'python',None]", 'hello', None, "(1,'hello',None)"}
>>> None in s
True
>>> s.pop()
'world'
>>> s.pop()
"[1,2,'python',None]"
>>> s.pop()
'hello'


"""

output = open("lesson3.txt","w",)
output.write(content)
output.close()